package com.cloud.tsp.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.api.domain.screen.ModelMileage;
import com.cloud.api.domain.screen.VehicleStatistics;
import com.cloud.api.domain.tsp.VehicleMileage;
import com.cloud.tsp.config.MysqlConfig;
import com.cloud.tsp.mapper.VehicleMileageMapper;
import com.cloud.tsp.service.IVehicleMileageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * @author 杨斌
 * 2024-02-1/2/2024
 */
@Service("vehicleMileageService")
public class VehicleMileageServiceImpl extends ServiceImpl<VehicleMileageMapper, VehicleMileage> implements IVehicleMileageService {

    @Resource
    private VehicleMileageMapper vehicleMileageMapper;
    @Autowired
    private MysqlConfig mysqlConfig;

    @Override
    public List<VehicleMileage> getVehicleMileage() {

        return vehicleMileageMapper.getVehicleMileage();
    }

    @Override
    public List<com.cloud.api.domain.screen.VehicleMileage> getVehicleTop() {
        List<com.cloud.api.domain.screen.VehicleMileage> vehicleTop = vehicleMileageMapper.getVehicleTop();
        for (com.cloud.api.domain.screen.VehicleMileage vehicle : vehicleTop) {
            vehicle.setVin(StrUtil.hide(vehicle.getVin(), 8, 11));
        }
        return vehicleMileageMapper.getVehicleTop();
    }

    @Override
    public List<ModelMileage> getModelTop() {
        return vehicleMileageMapper.getModelTop();
    }

    @Override
    public List<VehicleStatistics> getTitleStatistics() {
        return vehicleMileageMapper.getTitleStatistics(mysqlConfig.getDataSource());
    }

    @Override
    public VehicleStatistics getTotalStatistics() {
        return vehicleMileageMapper.getTotalStatistics();
    }

}